import axios from '@/utils/request';

/**
 * 新增入库单
 */
export async function AddInorder(params) {
    const res = await axios.post('/InOrder/AddInorder',params);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}


/**
 * 更新入库单
 */
export async function UpdateInorder(params) {
    const res = await axios.post('/InOrder/UpdateInorder',params);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取采购订单查询分页列表
 */
 export async function QueryInorderByCondition(params) {
    const res = await axios.post('/InOrder/QueryInorderByCondition',params);

    console.log('QueryInorderByCondition res',res)
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}


/**
 * 选择采购单适配入库单明细
 */
export async function ChoosePurOrder(query) {
    const res = await axios.post('/InOrder/ChoosePurOrder',query);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id获取入库单
 */
 export async function QueryInorderById(id) {
    const res = await axios.get('/InOrder/QueryInorderById/'+id);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据供应商id获取补发数量提示
 */
export async function QueryInOrderRepairItemByCount(id) {
    const res = await axios.get('/InOrder/QueryInOrderRepairItemByCount?supplierId='+id);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取入库供应商需补发产品
 */
export async function QueryInOrderRepairItemByCondition(params) {
    const res = await axios.post('/InOrder/QueryInOrderRepairItemByCondition',params);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}


/**
 * 入库单明细查询
 */
export async function QueryInorderItemByCondition(params) {
    const res = await axios.post('/InOrder/QueryInorderItemByCondition',params);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 打印
 */
export async function PrintInOrderById(id) {
    const res = await axios.post('/InOrder/PrintInOrderById?id='+id);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}


/**
 * 入库单审核
 */
export async function AuitInorder(params) {
    const res = await axios.post('/InOrder/AuitInorder',params);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 入库单反审核
 */
export async function AntiInorder(id) {
    const res = await axios.post('/InOrder/AntiInorder?id='+id);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 作废入库单
 */
export async function DeleteInorder(id) {
    const res = await axios.post('/InOrder/DeleteInorder?id='+id);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 导入期初入库单
 */
export async function ImportExcel(params) {
    const res = await axios.post('/InOrder/ImportExcel',params);
    if (res.data.code === 200) {
        return res.data;
    }
    return Promise.reject(new Error(res.data.msg));
}



